//
//  LocalNotification.swift
//  999-考勤定位
//
//  Created by 李晓东 on 2018/4/12.
//  Copyright © 2018年 PeanutXu. All rights reserved.
//

import UIKit

class LocalNotification: NSObject, UIApplicationDelegate {

    var application : UIApplication!
    var localNotification : UILocalNotification!
    func initLocalNotification() -> UIApplication {
        application = UIApplication.shared
        
        if #available(iOS 8.0, *) {
            application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.alert, .sound, .badge], categories: nil))
        }

        return application
    }
    
    func createLocalNoti() -> UILocalNotification {
        localNotification = UILocalNotification.init()
        localNotification.fireDate = Date(timeIntervalSinceNow: 10)
        localNotification.timeZone = NSTimeZone.default;
//        localNotification.soundName
        //        localNotification.repeatInterval 不需要重复
        localNotification.alertAction = "打开"
        localNotification.hasAction = true
        localNotification.alertBody = "真的好困啊"
        let info = ["key": "lixiaodong.org"]
        localNotification.userInfo = info
        return localNotification
        
    }
    
    func sendNotification(content : String) {
        localNotification.alertBody = content
        application.presentLocalNotificationNow(localNotification)
    }

}
